package com.gantzgulch.generics;

import static com.gantzgulch.generics.Cast.cast;

public class Pair<T, U> {

    public static <L,R> Pair<L,R> create(L left, R right){
        return new Pair<L,R>(left, right);
    }
    
    private T left;
    private U right;
    
    public Pair(){
        this(null, null);
    }
    
    public Pair(T left, U right){
        this.left = left;
        this.right = right;
    }

    public T getLeft() {
        return left;
    }

    public void setLeft(T left) {
        this.left = left;
    }

    public U getRight() {
        return right;
    }

    public void setRight(U right) {
        this.right = right;
    }
    
    @Override
    public int hashCode() {
    	return Objects.hashCode(left) + Objects.hashCode(right);
    }
    
    @Override
    public boolean equals(Object obj) {
    	
    	if( obj == null || ! (obj instanceof Pair<?,?>) ){
    		return false;
    	}
    	
    	Pair<T,U> pair = cast(obj);
    	return Objects.equals(left, pair.left) && Objects.equals(right, pair.right);
    }
    
}
